﻿using BLL;
using DataAccess;
using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;

namespace QuanLyKhachSan.FormThemCapNhat
{
    public partial class FormNhomTaiKhoanCapNhat : XtraForm
    {
        public NhomTaiKhoan nhomTaiKhoan = new NhomTaiKhoan();
        public bool IsInserted = false;
        private NhomTaiKhoanManager ntkManager = new NhomTaiKhoanManager();
        public FormNhomTaiKhoanCapNhat()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormNhomTaiKhoanCapNhat_Load(object sender, EventArgs e)
        {
           // lueditNhomQuyen.Properties.DataSource = new PhanQuyenManager().LayDanhSach().Result.ToList();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                nhomTaiKhoan.MaNhom = mtbMaNhom.Text;
                nhomTaiKhoan.TenNhom = txtTenNhom.Text;

                var validateRs = ntkManager.Validate(nhomTaiKhoan);
                if (validateRs.Valid())
                {
                    ActionResult actionResult;
                    actionResult = ntkManager.Them(nhomTaiKhoan);
                    if (!actionResult.Sucess())
                        XtraMessageBox.Show(actionResult.GetErrorMessage());
                    else
                    {
                        IsInserted = true;
                        Close();
                    }
                }
                else
                {
                    XtraMessageBox.Show(validateRs.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi nhập dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}
